package neuralNetwork;

import org.encog.neural.networks.BasicNetwork;

public class Erro {
	static double calcularErroMedioPercentualAbs(BasicNetwork net, double[][] in, double[][] out){
		double sum = 0;
		int n = 0;
		double[] previsao = new double[out[0].length];
		
		for(int i = 0; i<in.length; i++){
			net.compute(in[i], previsao);

			for(int j =0; j< previsao.length; j++){
			//	System.out.println(Math.abs(previsao[j]-out[i][j])/out[i][j]);
				sum += (Math.abs(out[i][j]-previsao[j])/out[i][j]);
				n++;
			}
			
		}
		
		return (100*sum/n);
	}
	
	static double calcularErroMedioQuadrado(BasicNetwork net, double[][] in, double[][] out){
		double sum = 0;
		int n = 0;
		double[] observado = new double[out[0].length];

		for(int i = 0; i<in.length; i++){
			net.compute(in[i], observado);

			for(int j =0; j< observado.length; j++){
				sum += (Math.pow(out[i][j]-observado[j],2));
				n++;
			}
			
		}
		
		return (sum/n);
	}

}
